package com.decent.ejfadmin.user.dao;

import com.decent.ejfadmin.user.bean.AdminRole;
import com.decent.ejfadmin.user.bean.ShiroButton;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * describe:按钮权限
 *
 * @author 陈豆豆
 * @date 2019/10/07
 */
@Mapper
@Repository
public interface AdminButtonShiroDao {
    /**
     * 获取当前用户按钮权限
     *
     * @param roleId
     * @return
     */
    @Select("select count(1) from yuhuang_shiro_role_btn where role_id=#{roleId}")
    int getBtnShiro(@Param("roleId") Integer roleId);

    /**
     * 删除按钮角色
     *
     * @param btnIds
     * @return
     */
    @Delete("delete from yuhuang_shiro_role_btn where button_id in(${btnIds}) ")
    int clearBtnBind(@Param("btnIds") String btnIds);

    /**
     * 重新绑定按钮权限
     *
     * @param roleId
     * @param btnId
     */
    @Update("insert into yuhuang_shiro_role_btn (role_id,button_id,gmt_create) VALUES (#{roleId},#{btnId},now())")
    void rebindButton(@Param("roleId") Integer roleId, @Param("btnId") Integer btnId);

    /**
     * 查询所有按钮
     *
     * @return
     */
    @Select("select id,btn_name from yuhuang_shiro_button")
    List<ShiroButton> getAllButton();

    /**
     * 获取所有角色
     *
     * @return
     */
    @Select("select id,name,code,is_available status,gmt_create createTime from tbl_shiro_role ")
    List<AdminRole> getAllRole();

    /**
     * 已绑定按钮
     *
     * @param roleId
     * @return
     */
    @Select("select b.btn_name from yuhuang_shiro_role_btn a,yuhuang_shiro_button b where a.button_id=b.id and a.role_id=#{roleId}")
    List<String> getBoundButton(@Param("roleId") Integer roleId);

    /**
     * 根据角色ID获取角色名称
     *
     * @param roleIds
     * @return
     */
    @Select("select id,name from tbl_shiro_role where id in (${roleIds}) ")
    List<AdminRole> queryBindRoleNameByRoleId(@Param("roleIds") String roleIds);

    /**
     * 已绑定按钮
     *
     * @param roleId 角色id
     * @return 按钮绑定记录数量
     */
    @Select("select count(1) from yuhuang_shiro_role_btn where role_id=#{roleId} and button_id = 2 ")
    int getTransferApplyBtn(Integer roleId);
}
